<?php

namespace App\Http\Middleware;

use Closure;
use Codeception\Module\Redis;

class LoginMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

        # 获取用户信息
//        session('userInfo');
        $userInfo = Redis::hget('userInfo');
        # 没有获取到用户信息、跳转登录页面、重新登录
        if (empty($userInfo)) {
            return  redirect('/login');
        }
        return $next($request);
    }
}
